package com.meng.menggaga.adapter;

import java.util.List;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.meng.menggaga.R;
import com.meng.menggaga.entity.CommunityInfos.CommunityInfo;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 首页广告页面
 * 
 * @author simba
 * 
 */
public class CommunityBannerAdapter extends PagerAdapter {
    private final Context mContext;
    private final List<CommunityInfo> mList;

    public CommunityBannerAdapter(Context context, List<CommunityInfo> list) {
        super();
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView icon =
                (ImageView) View.inflate(mContext, R.layout.viewpager_item_community_banner, null);
        ImageLoader.getInstance().displayImage(mList.get(position).cover_url, icon);
        container.addView(icon);
        return icon;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

}
